const express = require("express");

const router = express.Router();
const { ValidationError } = require("../utils/error");

const {
  findAllBlogTypeService,
  updateBlogTypeService,
  createBlogTypeService,
  deleteBlogTypeService,
  findByIdBlogTypeService,
} = require("../services/blogTypeServices");

// 新增
router.post("/", async (req, res) => {
  res.send(await createBlogTypeService(req.body));
});

// 删除
router.delete("/:id", async (req, res) => {
  if (!req.params.id) throw new ValidationError("id is required");
  res.send(await deleteBlogTypeService(req.params.id));
});

// 修改
router.put("/:id", async (req, res) => {
  if (!req.params.id) throw new ValidationError("id is required");
  res.send(await updateBlogTypeService(req.params.id, req.body));
});

// 查询
router.get("/:id", async (req, res) => {
  if (!req.params.id) throw new ValidationError("id is required");
  res.send(await findByIdBlogTypeService(req.params.id));
});

// 查询所有
router.get("/query/findAll", async (req, res) => {
  res.send(await findAllBlogTypeService());
});

module.exports = router;
